package fun.zhufn.oldcomm;

import fun.zhufn.oldcomm.model.bo.Path;
import fun.zhufn.oldcomm.model.service.PathManagerService;

import javax.swing.*;
import java.util.List;
import java.util.logging.Logger;

public class PathManagerController {
    private static final PathManagerController INSTANCE = new PathManagerController();
    private PathManagerController(){}
    public static PathManagerController getInstance() {
        return INSTANCE;
    }
    private static final Logger log = Logger.getLogger(PathManagerController.class.toString());

    public PathManagerService getPathSrv() {
        return oldSrv;
    }



    private final PathManagerService oldSrv = PathManagerService.getInstance();

    /**
     * @return 线路列表
     */
    public List<Path> getPathList() {
        return oldSrv.getPathList().getData();
    }

    /**
     * @param o 线路
     */
    public void addPath(Path o) {
        try {
            oldSrv.addPath(o);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "请检查线路代码是否重复");
            e.printStackTrace();
        }
    }

    /**
     * @param o 线路
     */
    public void editPath(Path o) {
        try {
            oldSrv.editPath(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param x 线路代码
     */
    public void removePath(String x) {
        try {
            if (!oldSrv.removePath(x)) {
                JOptionPane.showMessageDialog(null, "删除失败！");
            }
        } catch(Exception e) {
            JOptionPane.showMessageDialog(null, "删除失败！" + e);
        }
    }

    /**
     * @param code 线路代码
     * @param endTime 截止时间
     */
    public void setPathEnd(String code, int endTime) {
        try {
            oldSrv.setPathEnd(code, endTime);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "修改截止时间失败！\n" + e);
        }
    }
}
